<template>
	<view class="orderDetails">
		<view class="topBack">
			<!-- 物流信息 -->
			<view class="logisticsDiv" v-if="orderDetail.status!=0 && orderDetail.status!=4 && orderDetail.express_num">
				<view class="logisticsTop">
					<view class="logisticsTopLeft"></view>
					<text class="logisticsTopText">物流信息</text>
				</view>
				<view class="logisticsIn">
					<text class="logisticsInLeft">{{orderDetail.express_company}}</text>
					<text class="logisticsInRight" v-if="orderDetail.status==2">已发货</text>
				</view>
				<view class="logisticsBottom">快递编号：{{orderDetail.express_num}}</view>
			</view>
			<!-- 订单信息 -->
			<view class="orderDiv">
				<view class="orderTitle">
					<text class="orderTitleLeft">订单号:{{orderDetail.order_sn}}</text>
					<text class="orderTitleRight" v-if="orderDetail.status==0">待支付</text>
					<text class="orderTitleRight" v-if="orderDetail.status==1">待发货</text>
					<text class="orderTitleRight" v-if="orderDetail.status==2">待收货</text>
					<text class="orderTitleRight" v-if="orderDetail.status==3">已完成</text>
					<text class="orderTitleRight" v-if="orderDetail.status==4">售后中</text>
				</view>
				<view class="gang"></view>
				<view class="orderItemBottom" v-for="(itom,indox) in orderDetail.goods_info" :key="index">
					<view class="orderItemBottomLeft">
						<image class="orderItemBottomLeftImg" :src="itom.image"></image>
						<view class="orderItemBottomLeftRight">
							<text class="orderItemBottomLeftRightText">{{itom.title}}</text>
							<text class="orderItemBottomLeftRightBottom"><text
									class="orderItemfh">￥</text>{{itom.sum_price}}</text>
						</view>
					</view>
					<text class="gNum">共{{itom.goods_num}}件</text>
				</view>
				<view class="disbursementsDiv">
					<text class="disbursementsLeft">实付款</text>
					<view class="disbursementsRight">
						<text class="disbursementsRightLeft">商品总价</text>
						<text class="disbursementsRightRight"><text class="fh">￥</text>{{orderDetail.price}}</text>
					</view>
				</view>
				<view class="disbursementsDiv marginTop22">
					<text class="disbursementsLeft">运费</text>
					<view class="disbursementsRight">

						<text class="disbursementsRightRight fontClass"><text
								class="fh">￥</text>{{orderDetail.freight}}</text>
					</view>
				</view>
				<view class="gang marginTop29"></view>
				<view class="addressDiv">
					<text class="addressLeft">收货地址</text>
					<text class="addressRight">
						<template v-if="orderDetail.address">
							{{orderDetail.address.consignee}}，{{orderDetail.address.phone}}，{{orderDetail.address.address_name + orderDetail.address.address_details}}
						</template>
						<template v-else>
							地址不存在
						</template>
					</text>
				</view>
				<view class="productSnapshotDiv">
					<text class="productSnapshotLeft">商品快照</text>
					<view class="productSnapshotRight">
						<text class="productSnapshotRightText">核对交易细节时，可作为判断依据</text>
						<image class="productSnapshotRightImg"
							src="https://chongwu.aitaoba.net/storage/uploads/20231118/8a1ef58ba09c08e2c382762f0f5a8d14.png">
						</image>
					</view>
				</view>
				<view class="orderTimeDiv" v-if="orderDetail.create_time">
					<text class="orderTimeLeft">下单时间</text>
					<text class="orderTimeRight">{{orderDetail.create_time}}</text>
				</view>
				<view class="orderTimeDiv" v-if="orderDetail.send_time">
					<text class="orderTimeLeft">发货时间</text>
					<text class="orderTimeRight">{{orderDetail.send_time}}</text>
				</view>
				<view class="orderTimeDiv" v-if="orderDetail.pay_time">
					<text class="orderTimeLeft">成交时间</text>
					<text class="orderTimeRight">{{orderDetail.pay_time}}</text>
				</view>
				<!-- v-if="orderDetail.status == 4" -->
				<view class="kefuButtonDiv">
					<!-- <text class="orderTimeLeft">售后客服</text> -->
					<button class="kefuButton" open-type="contact">
						<text class="collectDivBottom buttonText">点击联系客服</text>
					</button>
				</view>

			</view>
		</view>
		<!-- 底部 -->
		<view class="buttomDiv" v-if="orderDetail.status==0">
			<view class="buttomLeft">
				合计：￥{{price}}
			</view>
			<view class="buttomRight" @click="moneyFun">立即支付</view>
		</view>
		<view class="buttomClass" v-if="(orderDetail.status==1||orderDetail.status==2 )&& orderDetail.express_num">

			<button class="bottomRightClass backButton" @click="reminder">催发货</button>
			<button class="bottomRightClass" @click="confirmReceipt">确认收货</button>
		</view>
		<view class="buttomClass" v-if="orderDetail.status!=0 && orderDetail.status!=4 && orderDetail.express_num">

			<!-- <button class="bottomRightClass backButton">删除订单</button> -->
			<button class="bottomRightClass" @click="handleLookLogistics">查看物流</button>

		</view>
	</view>
</template>

<script>
	import {
		orderDetail,
		reminder,
		delivery,
		orderPay
	} from '@/api/my.js'
	import {
		cateList,
		goodsList
	} from '@/api/shoppingMall.js'
	import {
		parse
	} from 'tough-cookie'
	export default {
		data() {
			return {
				orderState: 2,
				orderDetail: {},
				price: '0.00',
				orderId: ''
			}
		},
		/**
		 * 跳转到个人中心
		 */
		onBackPress(e) {

		},
		onPullDownRefresh() {

		},
		onShow() {


		},
		onReachBottom() {



		},

		onLoad(options) {
			console.log(options, '看看id')
			this.orderId = options.id
			this.getOrderDerails(options.id);
		},

		watch: {

		},
		methods: {
			// 查看物流
			handleLookLogistics() {
				console.log(this.orderId, 'idididi')
				uni.navigateTo({
					url: `/pages/logistics/logistics?id=${this.orderId}`
				})
			},

			reminder() {
				// orderDetail
				let data = {
					id: this.orderDetail.id
				};
				reminder(data).then((res) => {
					console.log(res, '催单999')
					if (res.code == 200) {
						uni.showToast({
							title: '催单成功',

						})
					}
				}).catch((res) => {})

			},
			confirmReceipt() {
				let data = {
					id: this.orderDetail.id
				};
				let that = this
				uni.showModal({
					title: '确定收货',
					content: '是否确定收货',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							delivery(data).then((res) => {
								if (res.code == 200) {
									uni.showToast({
										title: '已收货',

									})
									that.getOrderDerails(that.orderDetail.id);

								}
							}).catch((res) => {})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

			},
			moneyFun() {
				let data = {
					id: this.orderDetail.id
				};
				orderPay(data).then((res) => {
					console.log(res, '待支付订单唤起支付的参数')
					if (res.code == 200) {

						uni.requestPayment({
							provider: 'wxpay',
							timeStamp: res.data.timeStamp,
							nonceStr: res.data.nonceStr,
							package: res.data.package,
							signType: res.data.signType,
							paySign: res.data.paySign,
							success: function(res) {
								console.log('支付成功');
								uni.navigateTo({
									url: "/pages/myOrder/myOrder"
								})
							},
							fail: function(res) {
								console.log(res);
								console.log('支付失败');
							}
						});

					} else {
						uni.showToast({
							title: res.msg,

						})
					}
				}).catch((res) => {})


			},
			getOrderDerails(id) {
				let data = {
					id: id,
				};
				orderDetail(data).then((res) => {
					console.log(res, '订单详情666')
					if (res.code == 200) {
						this.orderDetail = res.data;
						this.orderDetail.address = res.data.address ? JSON.parse(res.data.address) : '';
						this.price = (parseFloat(this.orderDetail.price) + parseFloat(this.orderDetail.freight))
							.toFixed(2)
					}
				}).catch((res) => {})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.kefuButton {
		// max-width: 50rpx !important;
		// max-height: 72rpx !important;
		background: none !important;
		outline: none !important;
		border: none !important;

		border-radius: none !important;
		// margin-left: 48rpx !important;
		margin-right: 0rpx !important;
		padding-left: 0rpx !important;
		padding-right: 0 !important;
		line-height: none !important;
		display: flex;
		justify-content: flex-end;
		margin-top: 22rpx;
	}

	.kefuButton::after {
		outline: none !important;
		border: none !important;
	}

	.collectDivBottom {
		min-width: 52rpx !important;
		margin-top: 6rpx !important;
		font-size: 24rpx !important;

		color: #20a1f8 !important;
	}

	.buttonText {
		margin-top: 0 !important;
		transform: translate(0, -20%);
	}

	.orderDetails {
		width: 100%;
		display: flex;
		flex-direction: column;
	}

	.topBack {
		width: 750rpx;
		height: 216rpx;
		background: linear-gradient(180deg, #FAE24E 0%, rgba(250, 226, 78, 0) 100%);
		padding: 40rpx 30rpx 0rpx 30rpx;
		box-sizing: border-box;
	}

	.logisticsDiv {
		width: 690rpx;
		height: 237rpx;
		background: linear-gradient(180deg, #FFFCE6 0%, #FFFFFF 100%);
		border-radius: 20rpx;

		border: 4rpx solid #FFFFFF;
		display: flex;
		flex-direction: column;
		padding: 30rpx 48rpx 32rpx 31rpx;
		box-sizing: border-box;
	}

	.logisticsTop {
		display: flex;
		align-items: center;
	}

	.logisticsTopLeft {
		width: 8rpx;
		height: 30rpx;
		background: #FAE24E;
		border-radius: 4rpx;

		border: 1rpx solid #683518;
		box-sizing: border-box;
	}

	.logisticsTopText {
		font-size: 32rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #2E2908;
		margin-left: 9rpx;
	}

	.logisticsIn {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 28rpx;
	}

	.logisticsInLeft {
		font-size: 40rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #2E2908;
	}

	.logisticsInRight {
		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #2E2908;
	}

	.logisticsBottom {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #7A7A7A;
		margin-top: 6rpx;
	}

	.orderDiv {
		width: 690rpx;
		// height: 660rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		display: flex;
		flex-direction: column;
		padding: 32rpx 29rpx 32rpx 30rpx;
		box-sizing: border-box;
		margin-top: 20rpx;
	}

	.orderTitle {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.orderTitleLeft {
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #2E2908;
	}

	.orderTitleRight {
		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #20A1F8;
	}

	.gang {
		width: 100%;
		height: 1rpx;
		background: #D6D6D6;
		margin-top: 17rpx;
	}

	.orderItemBottom {
		width: 100%;
		display: flex;
		justify-content: space-between;
		margin-top: 30rpx;
	}

	.orderItemBottomLeft {
		display: flex;
		align-items: center;
	}

	.orderItemBottomLeftImg {
		width: 120rpx;
		height: 120rpx;
	}

	.orderItemBottomLeftRight {
		display: flex;
		flex-direction: column;
		margin-left: 20rpx;
	}

	.orderItemBottomLeftRightText {
		font-size: 30rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #2E2908;
	}

	.orderItemBottomLeftRightBottom {
		font-size: 36rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #EB1515;

	}

	.orderItemfh {
		font-size: 24rpx;
	}

	.gNum {
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #2E2908;
	}

	.disbursementsDiv {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 33rpx;
	}

	.disbursementsLeft {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #2E2908;
	}

	.disbursementsRight {
		display: flex;
		align-items: center;
	}

	.disbursementsRightLeft {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #ACACAC;

	}

	.disbursementsRightRight {
		font-size: 36rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #EB1515;
	}

	.fh {
		font-size: 24rpx;
	}

	.fontClass {
		color: #2E2908;
	}

	.marginTop22 {
		margin-top: 22rpx;
	}

	.marginTop29 {
		margin-top: 29rpx;
	}

	.addressDiv {
		display: flex;
		justify-content: space-between;
		margin-top: 22rpx;
	}

	.addressLeft {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #2E2908;
	}

	.addressRight {
		width: 437rpx;

		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #2E2908;
	}

	.productSnapshotDiv {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 21rpx;
	}

	.productSnapshotLeft {
		font-size: 27rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #2E2908;
	}

	.productSnapshotRight {
		display: flex;
		align-items: center;
	}

	.productSnapshotRightText {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #ACACAC;
	}

	.productSnapshotRightImg {
		width: 15rpx;
		height: 28rpx;
		margin-left: 11rpx;
	}

	.orderTimeDiv {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 22rpx;

	}

	.orderTimeLeft {
		font-size: 27rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #2E2908;
	}

	.orderTimeRight {
		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #2E2908;
	}

	.buttomDiv {
		width: 750rpx;
		height: 98rpx;
		background: #FFFFFF;
		border-radius: 0rpx;
		display: flex;
		justify-content: space-between;
		position: fixed;
		left: 0;
		bottom: 0;
	}

	.buttomClass {
		width: 750rpx;
		height: 98rpx;
		background: #FFFFFF;
		border-radius: 0rpx;

		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		// justify-content: flex-end;
		justify-content: flex-end;
		align-items: center;
		padding-right: 46rpx;
		box-sizing: border-box;
	}

	.bottomRightClass {
		width: 200rpx;
		height: 80rpx;
		background: #FED24C;
		border-radius: 10rpx;
		outline: none;
		border: none;
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #2E2908;
		text-align: center;
		line-height: 80rpx;

		margin: 0;
	}

	.backButton {
		background: #F1F2F6;
		margin-right: 20rpx;
	}


	.buttomLeft {
		width: 491rpx;
		height: 98rpx;
		padding: 27rpx 0 0 30rpx;
		box-sizing: border-box;

		color: #EB1515;
	}

	.buttomRight {
		width: 259rpx;
		height: 98rpx;
		background: #FED24C;
		border-radius: 0rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #5D5353;
		text-align: center;
		line-height: 98rpx;
	}
</style>